import socket
import pyzed.sl as sl
from GlobalValues import globalVal, CameraVal


def pointCould_socket():
    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    # 创建一个客户端链接,socket.AF_INET代表ipv4，socket.SOCK_STREAM代表tcp套接字
    client.connect(('127.0.0.1', 3005))
    # 客户端链接
    print('[+]  链接成功')
    # 链接成功显示
    while globalVal.pointCould_control:
        # A new image is available if grab() returns SUCCESS
        if CameraVal.zed.grab(CameraVal.runtime_parameters) == sl.ERROR_CODE.SUCCESS:
            # Retrieve colored point cloud. Point cloud is aligned on the left image.
            CameraVal.zed.retrieve_measure(CameraVal.point_cloud, sl.MEASURE.XYZRGBA)
            # for y in range(0, int(CameraVal.image_left.get_height()), 10):
            #     for x in range(0, int(CameraVal.image_left.get_width()), 10):
            #         # print('for循环开始')
            #         err, point_cloud_value = CameraVal.point_cloud.get_value(x, y)
            #         print(point_cloud_value)
            #
            # if len(str(point_cloud_value)) == 0:
            #     continue
            # client.send(str(point_cloud_value).encode('utf-8'))
            # print("数据发送成功")
            point_cloud_np = CameraVal.point_cloud.get_data()
            point_cloud_np.dot(CameraVal.tr_np)
            client.send(str(point_cloud_np).encode('utf-8'))
            print("数据发送成功")

    print('[+]  链接关闭...')

    client.close()
